const files = new Promise(resolve1 => {
	require('fs').readdir('./src', (err, f) => {
		resolve1(f[f.length - 1]);
	});
})
const {type} = require("os");
const browser = type() === "Windows_NT" ? "chrome"
	: type() === "Darwin" ? "Google Chrome" : "google-chrome"
;
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const reload = browserSync.reload;

const htmlMinHandler = async () => {
	let target = await files;
	return gulp.src(`./src/${target}/*`)
		.pipe(gulp.dest('./dist/'))
		.pipe(reload({stream: true}));
}
const watchHandler = async () => {
	let target = await files;
	browserSync.init({
		server: "./dist",
		browser,
		startPath: encodeURI(`/index.html`)
	});
	gulp.watch(`./src/${target}/*`, htmlMinHandler).on('change', reload);
}
module.exports.default = gulp.series(
	htmlMinHandler,
	watchHandler
);
